package com.czxy.demo01;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Test15 {
    public static void main(String[] args) {

        Map<String,String> map = new HashMap<>();
        String str = "<Dog name='小白' color='白色'  sons='小黑,小花'/>";
        String n = str.substring(str.indexOf("n"), str.indexOf("/")).replace("'","").replace("  "," ");
        String[] s = n.split(" ");
        System.out.println(Arrays.toString(s));
        for (String s1 : s) {
            String[] split = s1.split("=");

            map.put(split[0],split[1]);
        }

        Dog d = new Dog();
        d.setName(map.get("name"));
        d.setColor(map.get("color"));

        String sons = map.get("sons");
        String[] split = sons.split(",");
        for (String s1 : split) {
            d.getSons().add(s1);
        }

        System.out.println(d);


    }
}
